var projModule = angular.module("create", []);

projModule.controller("createCntrl", function($scope, $http){
	$scope.project = {id:"To be generated", name:"", serviceRequestId:"", custId:"", status:"New", description:"", plannedStartDate:"", plannedEndDate:"",
			actualStartDate:"",actualEndDate:"",managerRagStatus:"Amber",ragStatus:"Green"};
	$scope.create = function(project){
		project.id = "";
		$http.post("create", project).
			success(function(data, status) {
				$scope.status = status;
				$scope.project.id = data;
			});
	};
});

projModule.directive("datepicker", function() {
    return {
        restrict: "A",
        require : "ngModel",
        link : function (scope, element, attrs, ngModelCntrl) {
            $(function(){
                element.datepicker({
                    dateFormat:"dd-M-yy",
                    changeMonth:true,
                    changeYear:true,
                    showOtherMonths: true,
                    selectOtherMonths: true,
                    showAnim:"slideDown",
                    onSelect:function (date) {
                        ngModelCntrl.$setViewValue(date);
                        scope.$apply();
                    }
                });
                element.next().click(function(){
            		element.datepicker("show");
            	});
            });
        }
    };
});

$(document).ready(function() {
	expandProject();
});

function expandProject(){
	$("#projectDiv").on("shown", function () {
		$(".icon-circle-arrow-down").removeClass("icon-circle-arrow-down icon-white").addClass("icon-circle-arrow-up icon-white");
	});
	$("#projectDiv").on("hidden", function () {
		$(".icon-circle-arrow-up").removeClass("icon-circle-arrow-up icon-white").addClass("icon-circle-arrow-down icon-white");
	});
	$("#projectDiv").collapse("show");
}
